package com.qf.vue1.controller;

import com.qf.vue1.domain.R;
import com.qf.vue1.domain.Student;
import com.qf.vue1.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/stu")
public class StudentController {

    @Autowired
    private StudentMapper studentMapper;

    @GetMapping("/{number}")
    public R findByNumber(@PathVariable("number") String number){
        Student stu = studentMapper.findByNumber(number);

        return R.success(stu);
    }

    @PostMapping
    public R update(@RequestBody Student stu){
        studentMapper.update(stu);
        return R.success(null,"更新成功");
    }

    @PostMapping("/test")
    //第一个参数接收时，使用的是springmvc原生的转换器进行数据转换，内部涉及到Date类型，默认支持的是yyyy/MM/dd的字符串格式，可以通过@DateTimeFormat修改
    public R test(Student paramsStu,@RequestBody Student stu,@RequestHeader("token") String token){
        System.out.println(paramsStu);
        System.out.println(stu);
        System.out.println(token);

        return R.success(null,"success...");
    }
}
